package org.wukl.vhr.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wukl.vhr.model.Hr;
import org.wukl.vhr.model.ResponseBean;
import org.wukl.vhr.model.Role;
import org.wukl.vhr.service.HrService;
import org.wukl.vhr.service.RoleService;


import java.util.List;

@RestController
@RequestMapping("/sys/hr")
public class HrController {
    @Autowired
    HrService hrService;
    @Autowired
    RoleService roleService;
    @GetMapping("/")
    public List<Hr> getAllHr(String keywords)
    {
        return hrService.queryAllHr(keywords);
    }
    @PutMapping("/")
    public ResponseBean updateHr(@RequestBody Hr hr)
    {
        if(hrService.updateHr(hr)==1)
        {
            return ResponseBean.responseSuccess("更新成功",hr);
        }
        return ResponseBean.responseError("更新失败");
    }
    @GetMapping("/getAllRoles")
    public List<Role> getAllRoles()
    {
        return roleService.getAllRoles();
    }
    @PutMapping("/updateRoles")
    public ResponseBean updateRoles(Integer hrId,Integer[] roleIds)
    {
        if(hrService.updateHrRoles(hrId,roleIds))
        {
            return ResponseBean.responseSuccess("角色更新成功");
        }
        return ResponseBean.responseError("角色更新失败");
    }
    @DeleteMapping("/{id}")
    public ResponseBean deleteHr(@PathVariable Integer id)
    {
        if(hrService.deleteHr(id)==1)
        {
            return ResponseBean.responseSuccess("人员删除成功");
        }
        return ResponseBean.responseError("人员删除失败");
    }


}
